package com.gxc.authcore.system.util;

import java.util.Date;

import com.whalin.MemCached.MemCachedClient;
import com.whalin.MemCached.SockIOPool;

public class CacheUtil {

	private static SockIOPool pool = SockIOPool.getInstance();
	private static MemCachedClient memCachedClient;

	private static MemCachedClient getMemCachedClient() {
		if (pool == null) {
			String memCachedServers = ParamUtil.get("memCachedServers");
			String[] servers = memCachedServers.split(",");
			pool.setServers(servers);
			pool.setFailover(true);
			pool.setInitConn(10);
			pool.setMinConn(5);
			pool.setMaxConn(250);
			pool.setMaintSleep(30);
			pool.setNagle(false);
			pool.setSocketTO(3000);
			pool.setAliveCheck(true);
			pool.initialize();
		}
		if (memCachedClient == null) {
			memCachedClient = new MemCachedClient();
		}
		return memCachedClient;
	}

	public static void set(String arg0, Object arg1) {
		getMemCachedClient().set(arg0, arg1);
	}

	public static void set(String arg0, Object arg1, Date arg2) {
		getMemCachedClient().set(arg0, arg1, arg2);
	}

	public static void set(String arg0, Object arg1, Integer arg2) {
		getMemCachedClient().set(arg0, arg1, arg2);
	}

	public static void set(String arg0, Object arg1, Date arg2, Integer arg3) {
		getMemCachedClient().set(arg0, arg1, arg2, arg3);
	}

	public static Object get(String arg0) {
		return getMemCachedClient().get(arg0);
	}

	public static Object get(String arg0, Integer arg1) {
		return getMemCachedClient().get(arg0, arg1);
	}

	public static Object get(String arg0, Integer arg1, boolean arg2) {
		return getMemCachedClient().get(arg0, arg1, arg2);
	}

}
